import 'package:chat/common/utils/storage.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../common/routers/index.dart';

class SplashController extends GetxController {
  SplashController();

  _initData() {
    update(["splash"]);
  }

  void onTap() {}

  @override
  void onInit() {
    super.onInit();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      _jumpToPage();
    });
  }

  @override
  void onReady() {
    super.onReady();
  }

  _jumpToPage() {
    final refreshToken = Storage().getRefreshToken();
    if (refreshToken.isEmpty) {
      _initData();
    } else {
      Get.offAllNamed(RouteNames.main);
    }
  }

  // 登录
  void onLoginTap() async {
    Get.toNamed(RouteNames.login);
  }

  // 注册
  void onRegisterTap() async {
    Get.toNamed(RouteNames.register);
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }

  @override
  void onClose() {
    super.onClose();
  }
}
